package com.example.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.Model.EssayRelated;


import java.util.ArrayList;

import sdstcom.lbq.one.R;

/**
 * Created by Administrator on 2017/1/7.
 */

public class EssayLvAdapter extends BaseAdapter {
    private ArrayList<EssayRelated.DataBean> data;
    private LayoutInflater inflater;
    private Context context;

    public EssayLvAdapter(ArrayList<EssayRelated.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         ViewHolder holder= null;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.item_essayrelated,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.title.setText(data.get(position).getHp_title());
        holder.author.setText(data.get(position).getAuthor().get(0).getUser_name());

        return convertView;
    }
    public class ViewHolder{
        private TextView title;
        private TextView author;

        public ViewHolder(View convertveiw) {
            title = (TextView) convertveiw.findViewById(R.id.essay_related_title_tv);
            author = (TextView) convertveiw.findViewById(R.id.essay_related_author_tv);
        }
    }
}
